#include "GraphicsScaleOperation.h"
#include <GraphicsBaseItem.h>

GraphicsScaleOperation::GraphicsScaleOperation(GraphicsBaseItemData& itemData, QObject* parent)
	:GraphicsBaseOperation(GraphicsOperationType::ScaleOperation_Enum, itemData, parent)
{

}

void GraphicsScaleOperation::onScale(qreal scale)
{
	// 设置子图元的缩放比
	for (GraphicsBaseItem* child : m_itemData.getChilds()) {
		const QPointF curPos = child->pos();
		// 获取未进行缩放的坐标
		const QPointF originPoint = curPos / child->getItemData().getItemScale();
		child->getItemData().setItemScale(scale);
		// 重新调整坐标
		const QPointF childPos = originPoint * scale;
		child->setPos(childPos);
	}
	m_itemData.saveContext();
}
